import request from '@/utils/request'

//提供调用提取商品数据接口的函数
export const getGoodsDataService = (GoodsData: any) => {
    return request.get('/Goods/gotData',{params: GoodsData})
}

//获取商品详细信息
export const getGoodsDetailDataService = (GoodsData: any) => {
    return request.get('/Goods/gotDetailData',{
        headers:{
            'id':GoodsData,
        }
    })
}

//分页获取该商家上架的所有商品
export const getGoodsByPageService = (params: any) => {
    return request.get('/Goods/gotDataByPage', {params:params});
}

//添加商品
export const addGoodsService = (goodsData: any) => {
    return request.post('/Goods/addGoods', goodsData);
}

//根据商家名+商品名获取商品信息
export const getGoodsByBusinessService = (data: Map<string, string>) => {
    const paramsObject = Object.fromEntries(data);
    return request.post('/Goods/getGoodsByBusiness', paramsObject);
}

//更新商品信息
export const updateGoodsService = (old_title: string, goods: any) => {
    return request.post('/Goods/updateGoods', 
        {
            'old_title': old_title,
            'new_goods': goods
        }
    );
}

//下架商品
export const deleteGoodsService = (data: Map<string, string>) => {
    const paramsObject = Object.fromEntries(data);
    return request.post('/Goods/deleteGoods', paramsObject);
}

//添加商品浏览记录
export const addBrowsingHistoryService = (data: any) => {
    return request.post('/browsingHistory/addBrowsingHistory', data);
}

//删除商品详情
export const deleteGoodsDetailsImageService = (data: any) => {
    return request.post('/GoodsDetail/delete',  null, {
        params: {
            goodsDetailsImage: data
        }
    });
}

//删除商品所有详情图片
export const deleteGoodsAllDetailsImagesService = (data: any) => {
    return request.post('/GoodsDetail/deleteAll',  null, {
        params: {
            id: data
        }
    });
}

//添加商品详情
export const addGoodsDetailsImageService = (image: any, id: any) => {
    return request.post('/GoodsDetail/add', {goodsDetailsImage: image}, {
        params: {
            ID: id
        }
    });
}

//修改商品详情
export const updateGoodsDetailsImageService = (image: any, id: any) => {
    return request.post('/GoodsDetail/change', {goodsDetailsImage: image}, {
        params: {
            ID: id
        }
    });
}

//获取商品详情
export const getGoodsDetailsImageService = (id: any) => {
    return request.post('/GoodsDetail/getGoodsDetails', null, {
        params: {
            ID: id
        }
    });
}

//删除商品封面图片
export const deleteGoodsImageService = (data: any) => {
    return request.post('/GoodsImages/delete',  null, {
        params: {
            goodsImages: data
        }
    });
}

//删除商品所有封面图片
export const deleteGoodsAllImagesService = (data: any) => {
    return request.post('/GoodsImages/deleteAll',  null, {
        params: {
            id: data
        }
    });
}

//添加商品封面
export const addGoodsImageService = (image: any, id: any) => {
    return request.post('/GoodsImages/add', {goodsImage: image}, {
        params: {
            ID: id
        }
    });
}

//修改商品封面
export const updateGoodsImageService = (image: any, id: any) => {
    return request.post('/GoodsImages/change', {goodsImage: image}, {
        params: {
            ID: id
        }
    });
}

//获取商品封面
export const getGoodsImageService = (id: any) => {
    return request.post('/GoodsImages/getGoodsImage', null, {
        params: {
            ID: id
        }
    });
}